package com.briup.day13;

import java.util.Comparator;
import java.util.Map;
import java.util.TreeMap;

/**
 * @author 谭梦寻
 * @version 1.1
 * TreeHash 有序排序 红黑树 键不能为null
 */
public class TestTreeMap {
    public static void main(String[] args) {
//        数据以key的排序方式进行存储 学生和老师对应关系 排序规则：学生学号，老师号
        Map<Student,Teacher> map = new TreeMap<>(new Comparator<Student>() {
            @Override
            public int compare(Student o1, Student o2) {
                return o1.getId()-o2.getId();//从小到大排序
            }
        });
        map.put(new Student(1),new Teacher(10));
        map.put(new Student(2),new Teacher(6));
        map.put(new Student(5),new Teacher(10));
        map.put(new Student(4),new Teacher(8));
        map.put(new Student(7),new Teacher(8));
        map.put(new Student(6),new Teacher(10));
        map.put(new Student(0),null);
        System.out.println(map);
    }
}
class Student {
    private int id;

    public int getId() {
        return id;
    }

    public Student(int id) {
        this.id = id;
    }

    @Override
    public String toString() {
        return "Student{" +
                "id=" + id +
                '}';
    }
}
class Teacher {
    private int id;

    public int getId() {
        return id;
    }

    public Teacher(int id) {
        this.id = id;
    }
}
